package com.asdan.seededu.web.controller;




import java.util.List;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.asdan.seededu.entity.security.SubProject;
import com.asdan.seededu.entity.security.SubProjectStep;
import com.asdan.seededu.entity.security.User;
import com.asdan.seededu.front.service.Product01Service;
import com.asdan.seededu.front.service.RegistService;
import com.asdan.seededu.front.service.impl.Product01ServiceImp;
import com.asdan.seededu.front.service.impl.RegistServiceImp;
import com.demo2do.core.web.interceptor.MenuSetting;

@Controller
@MenuSetting("menu-user")
@RequestMapping("project")
public class Product01Controller {
	
	@RequestMapping(value="/{spid}/{uid}/detail",method=RequestMethod.GET)
	public String datail(@PathVariable String uid,@PathVariable String spid,Model model) {
		Product01Service ps = new Product01ServiceImp();
		int Uid=0;
		int Pid=0;
		if(uid!=null&&!"".equals(uid)){
			Uid=Integer.parseInt(uid);
		}
		if(spid!=null&&!"".equals(spid)){
			Pid=Integer.parseInt(spid);
		}
		SubProject subpro=new SubProject();
		subpro=ps.getsubpro(Uid, Pid);
		List<SubProjectStep> list=ps.getLiucheng( Pid);
		model.addAttribute("steplist",list);
		model.addAttribute("subpro",subpro);
		model.addAttribute("uid",uid);
		model.addAttribute("spid",spid);
		
		return this.getSchoolList(model);
	}
	
	
	@RequestMapping(value="/saveInfo",method=RequestMethod.POST)
	public String saveInfo(String stepid,String spid,String uid,String cname,String ename,String sex, String birthday , String idcard , String passid, String address , String schoolenglishname , String schoolname,String grade,String phone,String qq,String email,String fatherphone,String motherphone,
			String fatheremail,String motheremail,Model model) {
		Product01Service ps = new Product01ServiceImp();
		int Uid=0;
		int Pid=0;
		int Stepid=0;
		int schoolid=0;
		if(uid!=null&&!"".equals(uid)){
			Uid=Integer.parseInt(uid);
		}
		if(spid!=null&&!"".equals(spid)){
			Pid=Integer.parseInt(spid);
		}
		if(stepid!=null&&!"".equals(stepid)){
			Stepid=Integer.parseInt(stepid);
		}
		if(schoolname!=null&&!"".equals(schoolname)){
			schoolid=Integer.parseInt(schoolname);
		}
		System.out.println(Pid+"vvvvvvvvvvvvvvvvv");
		boolean isSave=ps.saveInfo(Stepid, Pid,Uid, cname, ename, sex, birthday, idcard, passid, address, schoolenglishname, schoolid, grade, phone, qq, email, fatherphone, motherphone, fatheremail, motheremail);
		SubProject subpro=new SubProject();
		subpro=ps.getsubpro(Uid, Pid);
		model.addAttribute("subpro",subpro);
		List<SubProjectStep> list=ps.getLiucheng( Pid);
		model.addAttribute("steplist",list);
		model.addAttribute("uid",Uid);
		model.addAttribute("spid",Pid);
		if( isSave){
			model.addAttribute("message","保存成功");
			return "product02";
		}else{
			model.addAttribute("message","保存失败");
		    return "product01";
		}
	}
	/*
	@RequestMapping(value="/submitInfo",method=RequestMethod.POST)
	public String submitInfo(String uid,String cname,String ename,String sex, String birthday , String idcard , String passid, String address , String schoolenglishname , String schoolname,String grade,String phone,String qq,String email,String fatherphone,String motherphone,
			String fatheremail,String motheremail,Model model) {
		Product01Service ps = new Product01ServiceImp();
		boolean isSave=ps.submitInfo(uid, cname, ename, sex, birthday, idcard, passid, address, schoolenglishname, schoolname, grade, phone, qq, email, fatherphone, motherphone, fatheremail, motheremail);
		if( isSave){
			model.addAttribute("message","提交成功");
		}else
			model.addAttribute("message","提交失败");
	
		return "product01";
	}*/
	
	@RequestMapping(value="/schoollist")
	public String getSchoolList(Model model ) {
		RegistService rs = new RegistServiceImp() ;
		List list=rs.getSchools();
		
		model.addAttribute("list",list);
		return "product01";
	}
	
	
	
	
	@RequestMapping(value="/payInfo",method=RequestMethod.POST)
	public String payInfo(String stepid,String uid,String spid,String accountholder,String bankname,String bankaccountnumber,String transferamount,String transferdate,String picture ,Model model) {
		Product01Service ps = new Product01ServiceImp();
		int Uid=0;
		int Pid=0;
		int Stepid=0;
		if(stepid!=null&&!"".equals(stepid)){
			Stepid=Integer.parseInt(stepid);
		}
		if(uid!=null&&!"".equals(uid)){
			Uid=Integer.parseInt(uid);
		}
		if(spid!=null&&!"".equals(spid)){
			Pid=Integer.parseInt(spid);
		}
		boolean isPay=ps.payInfo( Stepid,Uid,Pid, accountholder, bankname, bankaccountnumber, transferamount, transferdate, picture);
		SubProject subpro=new SubProject();
		subpro=ps.getsubpro(Uid, Pid);
		List<SubProjectStep> list=ps.getLiucheng( Pid);
		model.addAttribute("steplist",list);
		model.addAttribute("subpro",subpro);
		model.addAttribute("uid",Uid);
		model.addAttribute("spid",Pid);
		List<SubProjectStep> stepidlist=ps.getLiucheng( Pid);
		model.addAttribute("steplist",stepidlist);
		if( isPay){
			model.addAttribute("message","缴费成功,待审核");
			return "product03";
		}else{
			model.addAttribute("message","缴费失败");
			
		}
		return "product02";
	}
	
	
	
	
	@RequestMapping(value="/getxieyiInfo",method=RequestMethod.POST)
	public String getXieyiInfo(String uid,String pid,Model model) {
		Product01Service ps = new Product01ServiceImp();
		int Uid=0;
		int Pid=0;
		
		if(uid!=null&&!"".equals(uid)){
			Uid=Integer.parseInt(uid);
		}
		if(pid!=null&&!"".equals(pid)){
			Pid=Integer.parseInt(pid);
		}
		
		
		User user=ps.getXieyiInfo(Uid, Pid);
			model.addAttribute("user",user);
			List<SubProjectStep> list=ps.getLiucheng( Pid);
			model.addAttribute("steplist",list);
			return "product03";
	}
	
	
	@RequestMapping(value="/xieyiSend",method=RequestMethod.POST)
	public String xieyiSend(String stepid,String uid,String pid,String expresstype,String senttime,String expressnumber,String state,Model model) {
		Product01Service ps = new Product01ServiceImp();
		int Uid=0;
		int Pid=0;
		int Stepid=0;
		if(uid!=null&&!"".equals(uid)){
			Uid=Integer.parseInt(uid);
		}
		if(pid!=null&&!"".equals(pid)){
			Pid=Integer.parseInt(pid);
		}
		if(stepid!=null&&!"".equals(stepid)){
			Stepid=Integer.parseInt(stepid);
		}
		boolean flag=ps.xieyiSend(Stepid,Uid, Pid, expresstype, senttime, expressnumber, state);
		if( flag){
			model.addAttribute("message","成功");
		}else
			model.addAttribute("message","失败");
	
		return "product03";
	}
	
	
}
